package com.hmdp;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.StringRedisTemplate;

import javax.annotation.Resource;

@SpringBootTest
public class UV {
    @Resource
    StringRedisTemplate stringRedisTemplate;

    @Test
    void testHyperLogLog() {
        // 准备数据用来装用户数据
        String[] users = new String[1000];
        for (int i = 0; i < 1000000; i++) {
            users[i % 1000] = "user_" + i;
            // 每一千条发送一次
            if(i > 0 && i % 1000 == 0) {
                stringRedisTemplate.opsForHyperLogLog().add("hll1", users);
            }
        }
        // 统计数量
        Long size = stringRedisTemplate.opsForHyperLogLog().size("hll1");
        System.out.println("size = " + size);
    }
}
